<template>
  <div class="app-container">
    <el-alert title="亲社会行为" type="success" :closable="false" show-icon style="margin-bottom: 20px;">
      <template slot>
        参与环保公益活动，为社会做贡献的同时提升个人信用分，让每一个善举都有回报。
      </template>
    </el-alert>

    <!-- 用户信用分展示 -->
    <el-row style="margin-bottom: 20px;">
      <el-col :span="24">
        <el-card>
          <div class="score-display">
            <span class="score-label">当前信用分：</span>
            <span class="score-value">{{ userScore }}</span>
            <span class="score-desc">分</span>
            <div class="score-growth">
              <span class="growth-label">本月通过亲社会行为获得：</span>
              <span class="growth-value">+{{ monthlyGrowth }}</span>
              <span class="growth-desc">分</span>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 亲社会行为分类 -->
    <el-tabs v-model="activeTab" @tab-click="handleTabClick">
      <el-tab-pane label="资源回收" name="recycle">
        <recycle-activity />
      </el-tab-pane>
      <el-tab-pane label="护水卫士" name="water">
        <water-guardian />
      </el-tab-pane>
      <el-tab-pane label="公益之星" name="charity">
        <charity-star />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import RecycleActivity from './components/RecycleActivity.vue'
import WaterGuardian from './components/WaterGuardian.vue'
import CharityStar from './components/CharityStar.vue'
import { getUserStats } from '@/api/credit/prosocial'

export default {
  name: "CreditProsocial",
  components: {
    RecycleActivity,
    WaterGuardian,
    CharityStar
  },
  data() {
    return {
      userScore: 750,
      monthlyGrowth: 25,
      activeTab: 'recycle'
    };
  },
  created() {
    this.getUserScore();
  },
  methods: {
    /** 获取用户信用分 */
    getUserScore() {
      getUserStats().then(response => {
        if (response.code === 200) {
          this.userScore = response.data.creditScore || 750;
          this.monthlyGrowth = response.data.monthlyGrowth || 25;
        }
      }).catch(() => {
        // 使用默认值
      });
    },
    /** 切换标签页 */
    handleTabClick(tab) {
      this.activeTab = tab.name;
    }
  }
};
</script>

<style scoped>
.score-display {
  text-align: center;
  padding: 20px;
}

.score-label {
  font-size: 16px;
  color: #606266;
}

.score-value {
  font-size: 32px;
  font-weight: bold;
  color: #67C23A;
  margin: 0 8px;
}

.score-desc {
  font-size: 16px;
  color: #606266;
}

.score-growth {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #EBEEF5;
}

.growth-label {
  font-size: 14px;
  color: #909399;
}

.growth-value {
  font-size: 18px;
  font-weight: bold;
  color: #67C23A;
  margin: 0 5px;
}

.growth-desc {
  font-size: 14px;
  color: #909399;
}
</style> 